<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/prettyphoto.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.prettyphoto.js"></script>
<script type="text/javascript">
$(function(){
	$("a[rel^='pretty_photo']").prettyPhoto({theme:'facebook'});
	$("#weight").keypress(function(event){
		if (event.which == 13)
		{
			$(this).blur();
		}
	});
	$("#weight").focus(function(){
		$(this).select().removeClass('blur');
		old_weight = $(this).val();
	});
	$("#order_number").focus(function(){$(this).select();});
	<?if(isset($order)):?>$("#weight").focus();<?else:?>$("#order_number").select();<?endif;?>;
	$("#weight").blur(function(){
		var current_tag = $(this);
		var new_weight = $(this).val();
		var estimated_weight = $("#estimated_weight").val();
		if ((1 - new_weight/estimated_weight)>=0.3 || (1 - new_weight/estimated_weight)<=-0.3)
		{
			$("#estimated_weight").next().addClass('light_heigh');
		}
		else
		{
			$("#estimated_weight").next().removeClass('light_heigh');
		}
		var order_id = $(this).next().val();
		$.ajax({
			url: "<?=url('Storage::UKOverseas/WeighSave')?>&order_id="+order_id+"&weight="+new_weight,
			type: "GET",
			dataType: "json",
			success: function(data){
				if (data['ack'] != 1)
				{
					alert(data['message']);
				}
				$("#postage").html(data['postage']);
				current_tag.addClass('blur');
				$("#order_number").focus();
			}
		});
	});
});
</script>
<style>
.light_heigh {font-size: 15px; color: red; font-weight: bold;}
</style>
<fieldset>
<legend>查询</legend>
<form method="get">
<? include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<p>
	本地订单号：<input style="font-size: 1.3em;" autocomplete="off" id="order_number" type="text" size="30" name="number" value="<?=isset($_GET['number'])?$_GET['number']:''?>" />
	<input type="submit" class="button" value="查 询" />
</p>
</form>
</fieldset>
<?if (isset($order)):?>
<table width="70%" class="list_table">
<tr>
	<th>状态</th>
	<td><?=Helper_BSS_Normal::getIniOne('sales_order_handle_status', 'value', $order['handle_status'], 'name')?></td>
	<th>邮寄方式</th>
	<td><?=$order['shipping_method_name']?></td>
</tr>
<tr>
	<th>国家</th>
	<td><?=$order['country']?></td>
	<th>销售人员</th>
	<td><?=$order['user_name']?></td>
</tr>
<tr>
	<th>网站/店铺</th>
	<td><?=$order['shop_name']?></td>
	<th>网站单号</th>
	<td><?=$order['shop_order_number']?></td>
</tr>
<tr>
	<th>系统估算/实际称重</th>
	<td>
		<input type="hidden" id="estimated_weight" value="<?=$order['estimated_weight']?>" />
		<font <?if ($order['handle_status'] == Q::ini('custom_flag/sales_order_handle_status/weighed/value') && isset($order['estimated_weight']) && abs(($order['weight']-$order['estimated_weight'])/$order['estimated_weight']) >= 0.3)echo "class='light_heigh'"?>><?=sprintf('%.2f', $order['estimated_weight'])?> g</font> / 
		<input type="text" id="weight" class="blur" size="6" value="<?=($order['weight'])?sprintf('%.1f', $order['weight']):0?>" /> g
		<input type="hidden" value="<?=$order['id']?>" name="order_id" />
	</td>
	<th>运费计算</th>
	<td id="postage"><?=($order['postage']) ? $order['postage_currency_symbol'] . sprintf('%.2f', $order['postage']) : '0.00'?></td>
</tr>
<?if ($order['has_sales_notes']):?>
<tr>
	<th>销售备注</th>
	<td colspan="3" align="left">
		<?foreach ($order['sales_notes'] as $osn):?>
		<p><?=$osn['notes_name']?>(<?=$osn['add_time']?>):<?=$osn['notes']?></p>
		<?endforeach;?>
	</td>
</tr>
<?endif;?>
<?if ($order['has_warehouse_notes']):?>
<tr>
	<th>仓库备注</th>
	<td colspan="3" align="left">
		<?foreach ($order['warehouse_notes'] as $own):?>
		<p><?=$own['notes_name']?>(<?=$own['add_time']?>):<?=$own['notes']?></p>
		<?endforeach;?>
	</td>
</tr>
<?endif;?>
</table>
<table width="70%" class="list_table">
<tr>
	<th width="130">产品图片</th>
	<th width="100">产品编号</th>
	<th>产品属性</th>
	<th width="100">数量</th>
</tr>
<?foreach ($order['item'] as $oi):?>
<tr>
	<td>
		<?if ($oi['pic_url']):?>
			<?$pretty_photo_number = 0;?>
			<?foreach ($oi['pic_url'] as $oip):?>
			<a rel="pretty_photo[<?=$oi['id']?>]" href="<?=$oip?>"><?if(!$pretty_photo_number):?><img width="50" src="<?=$oip?>" /><?endif;?></a>
			<?$pretty_photo_number = 1;?>
			<?endforeach;?>
		<?endif;?>
	</td>
	<td><?=$oi['number']?></td>
	<td>
		<?foreach ($oi['attr'] as $oia):?>
		<p><?=$oia['name']?>:<?=$oia['value']?></p>
		<?endforeach;?>
	</td>
	<td><?=$oi['quantity']?></td>
</tr>
<?endforeach;?>
</table>
<?elseif (isset($wrong)):?>
<span class="red"><?=$wrong?></span>
<?endif;?>
<?php $this->_endblock();?>